package RecursiveSearcher;

import java.util.ArrayList;

/**
 * @ClassName LC230
 * @Description 二叉搜索树中第 k小的元素
 * @Author ZJX
 * @Date 2024/9/14 14:38
 * @Version 1.0
 */

//    https://leetcode.cn/problems/kth-smallest-element-in-a-bst/description/
public class LC230 {
    int count = 0;
    int result = 0;

    public int kthSmallest(TreeNode root, int k) {
        inoder(root,k);
        return result;
    }

    private void inoder(TreeNode root, int k) {
        if (root == null){
            return;
        }

        inoder(root.left,k);

        count++;
        if (count == k){
            result = root.val;
            return;
        }

        inoder(root.right,k);
    }
}
